from pathlib import Path
import time


def read_file_by_chunk_generator(filename, chunk_size=1024):

    file_path = Path(__file__).parent / filename
    with open(file_path, "r", encoding="utf-8") as f:

        while True:
            chunk = f.read(chunk_size)
            if not chunk:
                break
            else:
                yield chunk


file_read_gen = read_file_by_chunk_generator("large_file.txt")


while True:
    try:
        time.sleep(0.5)
        chunk = next(file_read_gen)
        print(chunk)

    except StopIteration as e:
        print("文件读取完毕")
        file_read_gen.close()
        break
